package cn.tedu.goods.management.service.impl;


import cn.tedu.goods.management.dao.persist.repository.IOrderRefundRepository;
import cn.tedu.goods.management.dao.persist.repository.IOrderRepository;
import cn.tedu.goods.management.pojo.eneity.OrderRefund;
import cn.tedu.goods.management.pojo.param.OrderRefundParam;
import cn.tedu.goods.management.service.IOrderRefundService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class OrderRefundServiceImpl implements IOrderRefundService {
    @Autowired
    private IOrderRefundRepository orderRefundRepository;
    @Autowired
    private IOrderRepository orderRepository;

    @Override
    public void refund(OrderRefundParam orderRefundParam) {
        OrderRefund orderRefund = new OrderRefund();
        BeanUtils.copyProperties(orderRefundParam,orderRefund);
        orderRefund.setRefundTime(LocalDateTime.now());
        orderRefund.setStatus((byte) 0);
        orderRefundRepository.insert(orderRefund);
        orderRepository.updateById(orderRefundParam.getOrderId());
    }

    @Override
    public void refundY(Long id) {
        orderRepository.updateByIdY(id);
    }

    @Override
    public void refundN(Long id) {
        orderRepository.updateByIdN(id);
    }

    @Override
    public List<OrderRefund> list() {
        return orderRefundRepository.getList();
    }

}
